package com.wx.wxpush.mapper;

import com.wx.wxpush.entiy.Letter;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface LetterMapper {
    //@Select("SELECT * FROM `letter` WHERE id >= (ROUND(((( SELECT MAX( id ) FROM `letter`)-( SELECT MIN( id ) FROM `letter`)) * RAND()),0) + ( SELECT MIN( id ) FROM `letter`)) LIMIT 1")
    @Select("select *,(SELECT count(id) from letter) as total from letter order by rand() limit 1")
    List<Letter> selectRoundBySql();

    @Insert("insert into  letter (letterInfo) values (#{letterInfo})")
    Boolean creatLetter(String letterInfo);

    @Update("UPDATE letter SET getCount =getCount+1 WHERE id =#{id} ")
    void updateGetter(String id);

    @Update("UPDATE letter SET likeCount =likeCount+1 WHERE id =#{id}")
    Boolean likeLetter(int id);
}
